package com.feishi.core.util.queue.disruptor;

import com.feishi.core.util.queue.Customer;
import com.feishi.core.util.queue.Producer;
import com.lmax.disruptor.RingBuffer;

/**
 * Created by caixq on 4/25 025.
 */
public class ProducerImpl<T> implements Producer {

    private RingBuffer<DisruptorData<T>> ringBuffer;

    public ProducerImpl(RingBuffer<DisruptorData<T>> ringBuffer) {
        this.ringBuffer=ringBuffer;
    }


    @Override
    public void push(Object value) {
        long sequence = ringBuffer.next();
        try {
            //用上面的索引取出一个空的事件用于填充
            DisruptorData event = ringBuffer.get(sequence);// for the sequence
            event.setValue(value);
        } finally {
            //发布事件
            ringBuffer.publish(sequence);
        }
    }

    @Override
    public void close() {

    }


}
